<template>
  <view class="content" :style="{ height: content + 'px', width:'100%' }"   >
	<image src="https://duxinai.com/images/nindex.png"  mode="scaleToFill"    :style="{ height: content + 'px', width:'100%' }"   />

	<view  class="btn" :style="{ top: btn + 'px'  }"  >
	<image src="https://duxinai.com/images/button.png"  style="height:100%; width:70%; "  @click="handleClick" />
	</view>
	
	<view  class="footer_txt" :style="{ top: (btn+60) + 'px'  }"  >
	您还有 <b style="color: blue"> {{countnum}} </b> 次测试机会
	</view>

	<view  style=" width:100%;height:50px; background-color: #272539;"  >
	</view>
  </view>
  <Chongzhi ref="czcom"  @callParentMethod="parentMethod" />
</template>




<script lang="ts" setup>
	import { ref } from 'vue'
	import TnPopup from '@/uni_modules/tuniaoui-vue3/components/popup/src/popup.vue'
	import TnButton from '@/uni_modules/tuniaoui-vue3/components/button/src/button.vue'
	import { userInfo, realUserInfo, reFlushToken  } from '@/api/login'
	import Chongzhi from './Chongzhi.vue'

	const countnum = ref(0);
	const czcom    = ref(null);
	const handleClick = () => {
		realUserInfo().then(res => {
			countnum.value = res.data.countnum
			if(countnum.value>0){
				uni.navigateTo({
					url:'/pages/upload/upload'
				});
				/*
				uni.redirectTo({
					url:'/pages/upload/upload'
				});*/
				
			}else{
				if (czcom.value) {
				  czcom.value.childMethod();
				}
			}
		})
	}
	
	//子类回调父类方法
	const parentMethod = () => {
		//刷新token
		reFlushToken()
		realUserInfo().then(res => {
			countnum.value = res.data.countnum
			uni.showToast({
			  icon: 'success',
			  title: '用户剩余点数：' + res.data.countnum,
			  duration: 3000 // 持续时间为3000毫秒，即3秒
			})
		}).catch(error => {
			console.error("111111111111111---error: " + error)
			uni.showToast({
			  icon: 'error',
			  title: '获取用户信息失败',
			  duration: 3000 // 持续时间为3000毫秒，即3秒
			})
		})
	}
 


	let content = ref(0)
	let btn     = ref(0)
	const getHeight = () => {
	    // 获取系统信息
	    uni.getSystemInfo({
	      success: (info) => {
	        // 页面的宽度和高度
			content.value =  info.screenHeight-10
			//content.value = info.windowHeight 
			btn.value = info.screenHeight - 175
			//content.value = { '--bg-height': windowHeight+' px' }
	      }
	    });
		
		
		userInfo().then(res => {
			console.log("--------ssssssssssssssssssssss------")
			console.log(res)
			console.log(res.data.countnum )
			countnum.value = res.data.countnum
		}).catch(error => {
			console.error("111111111111111---error: " + error)
			uni.showToast({
			  icon: 'error',
			  title: '获取用户信息失败',
			  duration: 3000 // 持续时间为3000毫秒，即3秒
			})
		})
	}
	getHeight()

</script>




<style>
	
 

.content {
	border: 0px solid red;
}

.amountview{
 border: 0px solid red;  width:95%;  border-radius: 20rpx; background-color: #EAEEF7; height:100%; display: block; 

}

.btn{
position: absolute; /* 设置为 absolute 进行绝对定位 */
border: 0px solid red;
width: 100%;
height: 80px;
display: flex; 
justify-content: center; 
align-items: center;
}

.footer_txt{
	position: absolute; /* 设置为 absolute 进行绝对定位 */
	border: 0px solid red;
	width: 100%;
	height: 80px;
	display: flex; 
	justify-content: center; 
	align-items: center;
	color: white;
}
</style>



